package cn.matezk.lianlian.controller;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.matezk.lianlian.beans.AliCloudResponse;
import cn.matezk.lianlian.service.INotifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("aliyun")
@Slf4j
public class AliCloudController {
    @Autowired
    private INotifyService notifyService;

    @PostMapping("smsReport")
    public AliCloudResponse report(@RequestBody List<JSONObject> reports) throws InterruptedException {
        log.info(JSONUtil.toJsonStr(reports));
        for (JSONObject report : reports) {
            notifyService.smsReport(report);
        }
        return AliCloudResponse.Success();
    }

    @PostMapping("ttsReport")
    public AliCloudResponse ttsReport(@RequestBody List<JSONObject> reports) throws InterruptedException {
        log.info(JSONUtil.toJsonStr(reports));
        for (JSONObject report : reports) {
            notifyService.ttsReport(report);
        }
        return AliCloudResponse.Success();
    }
}
